import request from '@/api/utils/request'


// 智能回答
export function register(form) {
  let target = '/register/'
  return request.post(target, form)
}

export function login(form) {
  let target = '/login/'
  return request.post(target, form)
}

export function sendingcode(email) {
  let target = '/send_email?'//拼凑Get请求来请求数据
  target += 'email=' + email
  return request.get(target)
}

export function modify(findback) {
  let target = '/modifypwd/'//拼凑Get请求来请求数据
  return request.post(target, findback)
}

export function getuserinfo(username) {
  let url = 'http://localhost:8000/userinfo?'//拼凑Get请求来请求数据
  url += 'username=' + username
  return request.get(url)
}

export function gettable(username) {
  let url = 'http://localhost:8000/returnfield?'//拼凑Get请求来请求数据
  url += 'username=' + username
  return request.get(url)
}



export function submit_mysql_info(form, attachment) {
  let url = 'http://localhost:8000/uploadmysql/'//拼凑Get请求来请求数据
  // console.log(form.username)
  // console.log(form.password)
  form.username = attachment.username
  form.field = attachment.field
  console.log(form)
  return request.post(url, form)
}

export function submit_mysql_detail(form, attachment, type) {
  let url = 'http://localhost:8000/mysqlinfo/'//拼凑Get请求来请求数据
  console.log(attachment)
  form.username = attachment.username
  form.field = attachment.field
  form.upload_type = type
  console.log(form)
  return request.post(url, form)
}



export function getdata(type) {
  let url = 'http://localhost:8000/readjson'//拼凑Get请求来请求数据
  return request.get(url)
}


export function updatefile(attachment) {
  let url = 'http://localhost:8000/uploadfile/'//拼凑Get请求来请求数据
  return request.post(url, {
    username: attachment.email,
    field: attachment.field
  })
}

export function calculate(id, attachment) {
  console.log(id)
  console.log(attachment)
  let url = 'http://localhost:8000/calculate/'//拼凑Get请求来请求数据
  return request.post(url, {
      id: id,
      username: attachment.username,
      field: attachment.field
    }
  )
}

export function get_user_fields(username) {
  let url = 'http://localhost:8000/returnfield?'//拼凑Get请求来请求数据
  url += 'username=' + username
  return request.get(url)
}

export function optimize(attachment, method) {
  let url = 'http://localhost:8000/optimize/'//拼凑Get请求来请求数据
  return request.post(url, {
    optimize_method: method,
    username: attachment.username,
    field: attachment.field
  })
}

export function deliver(newfield, username) {
  let url = 'http://localhost:8000/metricsdetail/'//拼凑Get请求来请求数据
  return request.post(url, {
    username: username,
    field: newfield.field_name,
    source: newfield.field_source,
    direction: newfield.field_direction,
    usage: newfield.field_use
  })
}

export function getdetail(username, field_name) {
  let url = 'http://localhost:8000/returnmetrics?'//拼凑Get请求来请求数据
  url += 'username=' + username
  url += '&field=' + field_name
  return request.get(url)
}

// export {
//   register
// }
